package top.huhuiyu.springboot3.entity.api;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@Data
@TableName("tb_data_history")
public class TbDataHistory implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    private Integer id;

    private String picUrl;
    private String title;
    private Integer year;
    private Integer month;
    private Integer day;
    private String details;

    @TableField(updateStrategy = FieldStrategy.NEVER, insertStrategy = FieldStrategy.NEVER)
    private Date created;

    public void fill(HistoryResult.HistoryData data) {
        this.setPicUrl(data.getPicUrl());
        this.setTitle(data.getTitle());
        this.setYear(data.getYear());
        this.setMonth(data.getMonth());
        this.setDay(data.getDay());
        this.setDetails(data.getDetails());
    }

    public static TbDataHistory from(HistoryResult.HistoryData data) {
        TbDataHistory history = new TbDataHistory();
        history.fill(data);
        return history;
    }

}
